﻿var Main = {	iscrolls : []};
$(function(){
	$('.emptypage').on('touchmove', function (event) {
		event.preventDefault();
	});
	page_url = encodeURI(location.href)
	//获取配置信息
	Main.get(url+'user/signaturePack',{url:page_url},function(res){
		if(res.ret==0){
			//执行成功
            appid_val = res.data.appId;
			timestamp_val = res.data.timestamp;
			nonceStr_val = res.data.nonceStr;
			signature_val = res.data.signature;
//	微信接口配置
			wx.config({
				debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
				appId: appid_val, // 必填，公众号的唯一标识
				timestamp: timestamp_val, // 必填，生成签名的时间戳
				nonceStr: nonceStr_val, // 必填，生成签名的随机串
				signature: signature_val,// 必填，签名，见附录1
				jsApiList: ["startRecord","onMenuShareAppMessage","stopRecord","playVoice","uploadVoice","stopVoice"] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
			});
			//wx.ready(function(){
			//	// config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
			//});
			//wx.error(function(res){
			//	//alert('error')
			//	// config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
            //
			//});
		}else{
			alert(res.msg)
			//执行失败
		}
	});
//	获取底部导航高度
	var botnav_h = $('.botnav').outerHeight()
	$('.station').height(botnav_h+10+'px')
	$('.questionanswering .determine,.probleminfor .recommend').css('margin-bottom',botnav_h+40+'px')
	$('.find_character .charactertype').css('margin-bottom',botnav_h+20+'px')

//	编辑信息
//	获取顶部导航高度
	header_h = $('.header').outerHeight()+6
////    设置距离顶部距离
//	$('.index,.newJin').css('marginTop',header_h)
//	$('.find_character,.find_problem').css('marginTop',header_h-6)
});
function link(url){
	location.href = url
}
var url = 'http://ekang.ren/'
//验证正则
obj={
	"phone":/^(((13[0-9]{1})|(14[0-9]{1})|(17[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/,
	"email":/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/,
	"name":/^[\u4e00-\u9fa5]+$/,
	"num":/^[1-9]+[0-9]*]*$/,
	"Idnumber":/^\d{17}[\w\d]$/,
};
//获取URL参数
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return unescape(r[2]); return null;
}
//alert弹层
function layer(content){
	$('body').append('<div class="elasticlayer animatescale" style=" z-index: 9999999999999; position: fixed; top:0; width: 100%; height:100%; background:rgba(0,0,0,.7) "><div class="elasticlayercon" style=" background: rgba(255,255,255,1); border-radius: 5px; width: 60%;position: absolute; left: 50%; top: 50%; -webkit-transform:translate(-50%, -50%);"><div class="tit" style=" width: 100%; color:#35424b; text-align: center; padding: 5% 0; font-size: 4vw">易康分答温馨提醒</div><p style=" width: 90%; margin: auto; text-align: center; font-size: 3.5vw; padding: 5% 0 10% 0; ">'+content+'</p><button style=" display: block; background: none; border: none; padding: 5% 0; font-size:4vw; color: #00b8ff; width: 100%; border-top: 1px solid #ddd; letter-spacing: 1px;">确定</button></div></div>')
	$('.elasticlayer .elasticlayercon button').live('click',function(){
		$('.elasticlayer').remove()
		$('.publicmask').remove()
	});
}
//get
Main.get = function(url, data, success) {
	$.ajax({
		type : 'get',
		url : url,
		dataType : 'jsonp',
		data : data,
		success : function(res) {
			if(res.ret==99){
				//location.href=response.url
				return ;
			}
			success(res);
		}
	});
}
//post
Main.post = function(url, obj, call) {
	if (!/^http/.test(url)) {
		url = url;
	}
	$.post(url, obj, function(response) {
		//console.log(response);
		if (call) {
			call(response)
		}
	}, 'json')
}
//加载
function Load(msg){
	$('body').append('<div class="progress" style=" width:90px;  height:67px; background:#000; opacity:0.7; position: absolute; left: 50%; top: 50%; -webkit-transform: translate(-50%, -50%); z-index:9999999; border-radius:5px;"><img src="../images/loader.gif" style="width:30%; margin-left:35%; margin-top:5%;"><p style=" text-align:center; margin-top:10px; color:#FFF;">'+msg+'</p></div>');
};
//验证
function prompt(msg){
	$('body').append('<div class="prompt" style=" width:100%;position:fixed; top:0; height:100%; background:rgba(0,0,0,0);"><div style=" padding: 10px 8px; background:#000; opacity:0.7; position: absolute; left: 50%; top: 50%; -webkit-transform: translate(-50%, -50%); z-index:9999999; border-radius:5px;"><p style=" text-align:center;  color:#FFF;">'+msg+'</p></div></div>');
	setTimeout("$('.prompt').fadeOut(2000)",1000);
	setTimeout("$('.prompt').remove()",1000);
};

function dropDown(obj,obj2,val){
	obj.on('click', function () {

		if ($$('.picker-modal.modal-in').length > 0) {
			myApp.closeModal('.picker-modal.modal-in');
		}
		myApp.pickerModal(
				'<div class="picker-modal" id="content-picker">' +
				'<div class="toolbar">' +
				'<div class="toolbar-inner">' +
				'<div class="left"></div>' +
				'<div class="right"><a href="#" class="close-picker">关闭</a></div>' +
				'</div>' +
				'</div>' +
				'<div class="picker-modal-inner">' +
				'<div class="content-block">' +
					// 数据
				'<div class="time-content" style="margin-top: -20px">'+
				'</div>'+

				'</div>' +
				'</div>' +
				'</div>'
		)
		//var today = new Date();
		var pickerInline = myApp.picker({
			input: obj2,
			container: '.time-content',
			toolbar: false,
			rotateEffect: true,
			//value: [today.getDate()],
			onChange: function (picker, values, displayValues) {
				var daysInMonth = new Date(picker.value[2], picker.value[0]*1 + 1, 0).getDate();
				if (values[1] > daysInMonth) {
					picker.cols[1].setValue(daysInMonth);
				}
			},
			cols: [val]
		});
		pickerInline;
	});
}
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return unescape(decodeURI(r[2])); return null;
}
////webViewJavaScript初始化
//function connectWebViewJavascriptBridge(callback) {
//	if (window.WebViewJavascriptBridge) {
//		callback(WebViewJavascriptBridge);
//	} else {
//		document.addEventListener('WebViewJavascriptBridgeReady', function() {callback(WebViewJavascriptBridge);}, false);
//	}
//}
//webViewJavaScript初始化
function connectWebViewJavascriptBridge(callback) {
	if (window.WebViewJavascriptBridge) {
		callback(WebViewJavascriptBridge);
	} else {
		document.addEventListener('WebViewJavascriptBridgeReady', function() {callback(WebViewJavascriptBridge);}, false);
	}
}
//空白页面
function pagenull(desc,url,buttonword){
	$('body').append('<div class="emptypage"><div class="con"><img src="images/icon27.png"><p>'+desc+'</p><button class=" ui-btn ui-shadow ui-corner-all">'+buttonword+'</button></div></div>')
	$('.emptypage .con button').live('click',function(){
		location.href=url
	});
	$('body').on('touchmove', function (event) {
		event.preventDefault();
	});
}